﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightingReflectionApp
{
    public class ReflectiveSurface
    {
        public double SquareSide { get; set; } // Размер элементарного квадрата
        public ReflectiveSquare[,] Squares { get; set; } // Матрица квадратов
        public Room Room { get; set; }

        public ReflectiveSurface(Room room)
        {
            SquareSide = room.SquareSide;
            Room = new Room(room.Length, room.Width, room.Height, room.SquareSide, room.FloorReflectionCoefficient, room.CeilingReflectionCoefficient);
            InitializeSquares(room);
        }

        private void InitializeSquares(Room room)
        {
            int rows = (int)(Room.Width / SquareSide);
            int cols = (int)(Room.Length / SquareSide);
            Squares = new ReflectiveSquare[rows, cols];

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    double x = j * SquareSide + SquareSide / 2;
                    double y = i * SquareSide + SquareSide / 2;
                    double reflectionCoefficient = 0;
                    double heightAboveFloor = 0;

                    foreach (var obj in room.ReflectiveObjects)
                    {
                        if (x >= obj.Location.X && x <= obj.Location.X + obj.Size.Width &&
                            y >= obj.Location.Y && y <= obj.Location.Y + obj.Size.Height)
                        {
                            reflectionCoefficient = obj.ReflectionCoefficient;
                            heightAboveFloor = obj.HeightAboveFloor;
                        }
                    }

                    Squares[i, j] = new ReflectiveSquare(x, y, reflectionCoefficient, heightAboveFloor);
                }
            }
        }
    }
}
